package com.burgeon.backend.SHOPBACKEND.controller;

import com.burgeon.backend.SHOPBACKEND.entity.Marketing;
import com.burgeon.backend.SHOPBACKEND.entity.MarketingItem;
import com.burgeon.backend.SHOPBACKEND.entity.QueryMarketingData;
import com.burgeon.backend.SHOPBACKEND.service.BackendMarketingService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("shopbackent/marketing")
public class BackendMarketingController extends BaseController {
    @Autowired
    private BackendMarketingService backendMarketingService;

    @RequestMapping("marketingStatistics")
    public ResponseResult<HashMap> getMarketingStatistics(String account, Integer state) {

        HashMap data = backendMarketingService.getMarketingStatistics(account, state);

        return new ResponseResult<HashMap>(SUCCESS, data);
    }

    @RequestMapping("marketingTemplateListData")
    public ResponseResult<ArrayList> marketingTemplateListData() {
        ArrayList data = backendMarketingService.marketingTemplateListData();
        return new ResponseResult<ArrayList>(SUCCESS, data);
    }

    /**
     * 发送活动模板
     *
     * @param queryMarketingData
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping("sendTemplate")
    public ResponseResult<Void> sendTemplate(QueryMarketingData queryMarketingData,
                                             String templateId, String first, String keyword1,
                                             String keyword2, String keyword3, String keyword4,
                                             String remark) {
        System.err.println(queryMarketingData);
        backendMarketingService.sendTemplate(queryMarketingData, templateId, first, keyword1, keyword2, keyword3, keyword4, remark);

        return new ResponseResult<>(SUCCESS);
    }

    /**
     * 发送套卷
     * @param queryMarketingData
     * @param giftId
     * @return
     */
    @RequestMapping("sendGiftCoupon")
    public ResponseResult<Void> sendGiftCoupon(QueryMarketingData queryMarketingData,String giftId) {
        System.err.println(queryMarketingData);
        backendMarketingService.batchCouponGift(queryMarketingData,giftId);
        return new ResponseResult<>(SUCCESS);
    }

    /**
     * 发送图文
     *
     * @param queryMarketingData
     * @param media_id
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping("sendNews")
    public ResponseResult<Void> sendNews(QueryMarketingData queryMarketingData, String media_id) throws UnsupportedEncodingException {
        System.err.println(queryMarketingData);
        backendMarketingService.sendWxNewsByOpenIds(queryMarketingData, media_id);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("execute")
    public ResponseResult<Void> execute(QueryMarketingData queryMarketingData) {
        System.err.println(queryMarketingData);
        backendMarketingService.batchAddCoupon(queryMarketingData);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("queryVip")
    public ResponseResult<ArrayList> queryVip(QueryMarketingData queryMarketingData) {
        System.err.println(queryMarketingData);
        ArrayList data = backendMarketingService.fingVipData(queryMarketingData);

        return new ResponseResult<ArrayList>(SUCCESS, data);
    }

    @RequestMapping("getDataList")
    public ResponseResult<ArrayList> getDataList(String str, String account) {
        String[] arr = str
                .replace("[", "")
                .replace("]", "")
                .split(",");
        ArrayList data = backendMarketingService.getDataList(arr, account);

        return new ResponseResult<ArrayList>(SUCCESS, data);
    }

    @RequestMapping("queryVipData")
    public ResponseResult<HashMap> queryVipData(String id, String str, String account, Integer start) {
        String[] arr = str
                .replace("[", "")
                .replace("]", "")
                .split(",");
        System.err.println(start);
        HashMap data = backendMarketingService.findVipData(id, arr, account, start);

        return new ResponseResult<HashMap>(SUCCESS, data);
    }

    @RequestMapping("data")
    public ResponseResult<List<Marketing>> getData(String account) {
        List<Marketing> data = backendMarketingService.getData(account);
        return new ResponseResult<List<Marketing>>(SUCCESS, data);
    }

    @RequestMapping("itemData")
    public ResponseResult<List<MarketingItem>> getItemData(String id, String account) {
        List<MarketingItem> data = backendMarketingService.getItemData(id, account);
        return new ResponseResult<List<MarketingItem>>(SUCCESS, data);
    }


}
